package com.epam.parser;

import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.StringTokenizer;

public class Word extends TextPart {

	public Word(String s) {
		super(s);
	}

	public Word() {
	}

	public static List<TextPart> divideToWords(List<TextPart> text) {
		String s = listToString(text);
		List<TextPart> words = new ArrayList<TextPart>();
		StringTokenizer st = new StringTokenizer(s, " \t\n\r,.();");
		while (st.hasMoreTokens()) {
			words.add(new Word(st.nextToken()));
		}
		return words;
	}

	public static List<Word> readWordsToCompare(String fileName) {
		List<Word> wordsToCompare = new ArrayList<Word>();
		Properties p = new Properties();
		String s;
		
		try {
			p.load(new FileReader(fileName));
			for (int i = 1; i <= p.size(); i++) {
				s = String.valueOf(i);
				wordsToCompare.add(new Word(p.getProperty(s)));
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return wordsToCompare;
		
	}
	
	public static Word[] listToArray(List<Word> part) {
		Word[] parts = new Word[part.size()];
		for (int i = 0; i<part.size(); i++) {
			parts[i] = part.get(i);			
		}
		return parts;

	
}
}
